<?php
session_start();
if(!isset($_SESSION["login"])){
header ("Location: index.php");
}
echo $_SESSION["caja"];if(isset($_GET["leave"])){
	session_destroy();
	header ("Location: index.php");
	}
include "includes/conexion.php";
	function comprueba_area($grupo,$area){
	$consulta="SELECT * FROM s_axg_actgrps WHERE saxg_grupo='$grupo' AND saxg_area='$area'";

	$qry=mysql_query($consulta);
	$resultado=false;
	while($row=mysql_fetch_row($qry)){
		$resultado=true;
	}
	if($resultado>0){
		return TRUE;
	}
	else{
		return FALSE;
	}
}
	function comprueba_actividad($grupo,$actividad,$area){
	$consulta="SELECT * FROM s_axg_actgrps WHERE saxg_grupo='$grupo' and saxg_area='$area'and saxg_actividad='$actividad'";
//echo $consulta;
	$qry=mysql_query($consulta);
	$resultado=false;
	while($row=mysql_fetch_row($qry)){
		$resultado=true;
	}
	if($resultado>0){
		return TRUE;
	}
	else{
		return FALSE;
	}
}
?>
<!DOCTYPE HTML>
<html lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>ScMarket</title>
		<link rel="stylesheet" type="text/css" href="css/960.css" />
		<link rel="stylesheet" type="text/css" href="css/reset.css" />
		<link rel="stylesheet" type="text/css" href="css/text.css" />
		<link rel="stylesheet" type="text/css" href="css/blue.css" />
		<link type="text/css" href="css/smoothness/ui.css" rel="stylesheet" />
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
		<!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> ojo-->
		<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
		
		<script type="text/javascript" src="includes/asistente/sliding.form.js"></script>
		<script type="text/javascript" src="includes/asistente/sliding.form.edit.js"></script>
		<script type="text/javascript" src="js/blend/jquery.blend.js"></script>	
		<script type="text/javascript" src="js/ui.core.js"></script>
		<script type="text/javascript" src="js/ui.sortable.js"></script>
		<script type="text/javascript" src="js/ui.dialog.js"></script>
		<script type="text/javascript" src="js/ui.datepicker.js"></script>
		<script type="text/javascript" src="js/effects.js"></script>
		<script type="text/javascript" src="js/flot/jquery.flot.pack.js"></script>
		<script type="text/javascript" src="js/js_super.js"></script>
		<script type="text/javascript" src="js/jd_super_asistente.js"></script>
		<script type="text/javascript" src="js/jquery.chromatable.js"></script>
		<script type="text/javascript" src="js/jquery.Rut.min.js"></script>
		<script type="text/javascript" src="js/jquery.Rut.js"></script>
				

    <script>//check de nuevo producto 
$(document).ready(function(){
	
    $("#check_formula").click(function() {  
       if($("#check_formula").is(':checked')) {  
            $("#valor_uno").removeAttr("disabled"); 
            $("#valor_dos").removeAttr("disabled"); 
        } else {  
            $("#valor_uno").attr("disabled", "disabled");
            $("#valor_dos").attr("disabled", "disabled");  
        } 
    }); 
    	}); 
    	$(document).ready(function(){
    $("#check_oferta").click(function() { 
			if($("#check_oferta").is(':checked')) { 
        	 $("#prueba").removeAttr("disabled"); 
            $("#producto_oferta").removeAttr("disabled"); 
            $("#fecha_inicio").removeAttr("disabled"); 
             $("#fecha_fin").removeAttr("disabled"); 
              $("#cantidad_oferta").removeAttr("disabled"); 
              $("#targeta_local").removeAttr("disabled"); 
              $("#descuento").removeAttr("disabled");
              $("#valor_ultimo").removeAttr("disabled"); 
              $("#segundo_producto").removeAttr("disabled"); 
              $("#nombre_oferta").removeAttr("disabled"); 
        } else {  
        	$("#prueba").attr("disabled", "disabled");
            $("#producto_oferta").attr("disabled", "disabled");
            $("#fecha_inicio").attr("disabled", "disabled"); 
            $("#fecha_fin").attr("disabled", "disabled");
            $("#cantidad_oferta").attr("disabled", "disabled");
            $("#targeta_local").attr("disabled", "disabled");
            $("#descuento").attr("disabled", "disabled");
            $("#valor_ultimo").attr("disabled", "disabled");
            $("#segundo_producto").attr("disabled", "disabled");    
            $("#nombre_oferta").attr("disabled", "disabled");         
        } 
        }); 

    }); 	
$(document).ready(function(){
	$("#codigo_barra").blur(function(){
		//$("#destino").css("display", "inline");
		var data = $("#codigo_barra").val();
		
		$("#destino").load("includes/funciones.php?verifica="+data, function(){
			$("#destino").css("display", "inline");
		});

	});
	$("#codigo_barra").focus(function(){
		$("#destino").css("display", "none");
	});
});
$(document).ready(function(){
	$("#codigo_prod").blur(function(){
		//$("#destino").css("display", "inline");
		var data = $("#codigo_prod").val();
		
		$("#destino").load("includes/funciones.php?verifica_prod="+data, function(){
			$("#destino").css("display", "inline");
		});

	});
	$("#codigo_prod").focus(function(){
		$("#destino").css("display", "none");
	});
});
</script>
    <script>//check de nuevo producto 
$(document).ready(function(){
	
    $("#check_formula2").click(function() {  
       if($("#check_formula2").is(':checked')) {  
            $(".formula").removeAttr("disabled"); 
            //$(".formula").removeAttr("disabled"); 
        } else {  
            $(".formula").attr("disabled", "disabled");
            //$(".formula").attr("disabled", "disabled");  
        } 
    }); 
    	}); 
    	$(document).ready(function(){
    $("#check_oferta2").click(function() { 
			if($("#check_oferta2").is(':checked')) { 
        	 $(".oferta").removeAttr("disabled"); 
            /*$("#producto_oferta").removeAttr("disabled"); 
            $("#fecha_inicio").removeAttr("disabled"); 
             $("#fecha_fin").removeAttr("disabled"); 
              $("#cantidad_oferta").removeAttr("disabled"); 
              $("#targeta_local").removeAttr("disabled"); 
              $("#descuento").removeAttr("disabled");
              $("#valor_ultimo").removeAttr("disabled"); 
              $("#segundo_producto").removeAttr("disabled"); */
        } else {  
        	$(".oferta").attr("disabled", "disabled");
            /*$("#producto_oferta").attr("disabled", "disabled");
            $("#fecha_inicio").attr("disabled", "disabled"); 
            $("#fecha_fin").attr("disabled", "disabled");
            $("#cantidad_oferta").attr("disabled", "disabled");
            $("#targeta_local").attr("disabled", "disabled");
            $("#descuento").attr("disabled", "disabled");
            $("#valor_ultimo").attr("disabled", "disabled");
            $("#segundo_producto").attr("disabled", "disabled");  */          
        } 
        }); 

    }); 	
$(document).ready(function(){
	$("#codigo_barra2").change(function(){
		//$("#destino").css("display", "inline");
		var data = $("#codigo_barra2").val();
		
		$("#destino2").load("includes/funciones.php?verifica="+data, function(){
			$("#destino2").css("display", "inline");
		});

	});
	$("#codigo_barra2").focus(function(){
		$("#destino2").css("display", "none");
	});
});
</script>
		<script>
			$(document).ready(function() {			
				$("#box-table-a").chromatable({

					width : "900px",
					height : "400px",
					scrolling : "yes"

				});
			});
		</script>
		<script type="text/javascript" src="js/genera_tabla.js"></script>
				    <script>
$(document).ready(function(){
	$('#ocultar').click(function() {
		   $('#cale').css("display","none"); 
	});
	$('#mostrar').click(function() {
		    $('#cale').css("display","block");   
	});
});
$(document).ready(function(){
	$("#registrarg").attr("disabled", "disabled");
	$("#areas").click(function(){
		data=$("#areas").val();
		$("#actividad_div").load("includes/funciones.php?area="+data,function(){
			$("#registrarg").removeAttr("disabled"); 
		});
	});
});

$(document).ready(function(){
	$("#registrarg").attr("disabled", "disabled");
	$("#areas2").click(function(){
		data=$("#areas2").val();
		$("#actividad_div2").load("includes/funciones.php?area="+data,function(){
			$("#registrarg").removeAttr("disabled"); 
		});
	});
});
$(document).ready(function(){
	$("#margen").focus(function(){
		
		margen=((($("#precio_venta").val() / $("#precio_costo").val())-1)*100);
		$("#margen").val(Math.round(margen*100)/100);
		
	});
		$("#margen2").focus(function(){
		
		margen=((($("#precio_venta2").val() / $("#precio_costo2").val())-1)*100);
		$("#margen2").val(Math.round(margen*100)/100);
		
	});
$("#rut").Rut({
  digito_verificador: $("#dv"),
  on_error: function(){ 
  	$("#rut").val("");
  	$("#dv").val("");
  	alert('Rut incorrecto'); }
});
});

    </script>


		
		<?php //identificar formulario editar
		if (isset($_GET["editar"])) {
			switch ($_GET["subsec"]) {
				case 'proveedores' :
					echo "<a href='#login-box2' id='subsec' class='hidden'></a>";
					break;
				case 'categorias' :
					echo "<a href='#login-box-cat-edit' id='subsec' class='hidden'></a>";
					break;
				case 'subcategorias' :
					echo "<a href='#login-box-subcat-edit' id='subsec' class='hidden'></a>";
					break;
				case 'sucursales' :
					echo "<a href='#login-box-suc-edit' id='subsec' class='hidden'></a>";
					break;
				case 'cajas' :
					echo "<a href='#login-box-cja-edit' id='subsec' class='hidden'></a>";
					break;
				case 'cajeros' :
					echo "<a href='#login-box-caj-edit' id='subsec' class='hidden'></a>";
					break;
				case 'envases' :
					echo "<a href='#login-box-env-edit' id='subsec' class='hidden'></a>";
					break;
				case 'bodegas' :
					echo "<a href='#login-box-bod-edit' id='subsec' class='hidden'></a>";
					break;
				case 'formas_pagos' :
					echo "<a href='#login-box-fp-edit' id='subsec' class='hidden'></a>";
					break;
				case 'clientes' :
					echo "<a href='#login-box-cli-edit' id='subsec' class='hidden'></a>";
					break;
				case 'productos' :
					echo "<a href='#login-box-pro-edit' id='subsec' class='hidden'></a>";
					break;
				case 'usuarios' :
					echo "<a href='#login-box-usr-edit' id='subsec' class='hidden'></a>";
					break;
				case 'grupos' :
					echo "<a href='#login-box-grp-edit' id='subsec' class='hidden'></a>";
					break;
			}
			echo "
<script type='text/javascript' src='js/js_super2.js'></script>
";

		}
		?>

		<!--[if IE]>
		<script language="javascript" type="text/javascript" src="js/flot/excanvas.pack.js"></script>
		<![endif]-->
		<!--[if IE 6]>
		<link rel="stylesheet" type="text/css" href="css/iefix.css" />
		<script src="js/pngfix.js"></script>
		<script>
		DD_belatedPNG.fix('#menu ul li a span span');
		</script>
		<![endif]-->
		<script id="source" language="javascript" type="text/javascript" src="js/graphs.js"></script>

	</head>

	<body>
		<!-- WRAPPER START -->
		<div class="container_16" id="wrapper">
			<!-- HIDDEN COLOR CHANGER -->
			<div style="position:relative;">
				<div id="colorchanger">
					<a href="dashboard_red.html"><span class="redtheme">Red Theme</span></a>
					<a href="dashboard.html"><span class="bluetheme">Blue Theme</span></a>
					<a href="dashboard_green.html"><span class="greentheme">Green Theme</span></a>
				</div>
			</div>
			<!--LOGO-->
			<div class="grid_8" id="logo">
				ScMarket - Aadministracion de su negocio
			</div>
			<div class="grid_8">
				<!-- USER TOOLS START -->
				<div id="user_tools">
					<span><a href="#" class="mail">(0)</a> Bienvenido <a href="#"><?php echo ucfirst($_SESSION["nombre"]) ?></a> <!--|  <a class="dropdown" href="#">Change Theme</a> --> | <a href="menu.php?leave=1">Salir</a></span>
				</div>
			</div>
			<!-- USER TOOLS END -->
			<div class="grid_16" id="header">
				<!-- MENU START -->
				<!-- PRIMER BARRA -->
				<?php
				function actual($li) {
					if (isset($_GET["sec"])) {
						$acc = $_GET["sec"];
						if ($acc == $li) {
							echo "class='main current'";
						}
					}
				}
				?>
				<div id="menu">
					<ul class="group" id="menu_group_main">
						
						<?php if(comprueba_area($_SESSION["grupo"],ucwords("mant"))){?>
						<li class="item first" id="one">
							<a href="#" <?php actual("mantencion"); ?> onclick="window.location='?sec=mantencion&subsec=proveedores'"><span class="outer"><span class="inner dashboard">Mantenciones</span></span></a>
						</li>
						<?php }?>
						<?php if(comprueba_area($_SESSION["grupo"],ucwords("mant"))){?>
						<li class="item middle" id="two">
							<a href="#" <?php actual("ventas"); ?> onclick="window.location='?sec=ventas'"><span class="outer"><span class="inner content">Ventas</span></span></a>
						</li>
						<?php }?>
						<!--<li class="item middle" id="three"><a href="#"><span class="outer"><span class="inner reports png">Reports</span></span></a></li>-->
						<li class="item middle" id="four">
							<a href="#" class="main"><span class="outer"><span class="inner users">Usuarios</span></span></a>
						</li>
						<li class="item middle" id="five">
							<a href="#" class="main"><span class="outer"><span class="inner media_library">Media Library</span></span></a>
						</li>
						<li class="item middle" id="six">
							<a href="#" class="main"><span class="outer"><span class="inner event_manager">Event Manager</span></span></a>
						</li>
						<li class="item middle" id="seven">
							<a href="#" class="main"><span class="outer"><span class="inner newsletter">Newsletter</span></span></a>
						</li>
						<li class="item last" id="eight">
							<a href="#" class="main"><span class="outer"><span class="inner settings">Settings</span></span></a>
						</li>
					</ul>
				</div>
				<!-- MENU END -->
			</div>

			<?php
			if (isset($_GET["sec"])) {
				$sec = $_GET["sec"];
				switch ($sec) {
					case "mantencion" :
						if (isset($_GET["subsec"])) {
							$subsec = $_GET["subsec"];
							switch ($subsec) {
								case "proveedores" :
									include "mantenedores/man_proveedor.php";
									break;
								case "categorias" :
									include "mantenedores/man_categoria.php";
									break;
								case "subcategorias" :
									include "mantenedores/man_subcategoria.php";
									break;
								case "productos" :
									include "mantenedores/man_producto.php";
									break;
								case "sucursales" :
									include "mantenedores/man_sucursal.php";
									break;
								case "cajas" :
									include "mantenedores/man_caja.php";
									break;
								case "cajeros" :
									include "mantenedores/man_cajero.php";
									break;
								case "envases" :
									include "mantenedores/man_envase.php";
									break;
								case "bodegas" :
									include "mantenedores/man_bodega.php";
									break;
								case "formas_pagos" :
									include "mantenedores/man_formas_pago.php";
									break;
								case "clientes" :
									include "mantenedores/man_cliente.php";
									break;
								case "usuarios" :
									include "mantenedores/man_usuario.php";
									break;
								case "grupos" :
									include"mantenedores/man_grupo.php";
									break;
							}
						}

						break;
						case "ventas":
							header ("Location: venta/venta.php");
						break; 

					case 2 :
						echo "i es igual a 2";
						break;
				}
			}
			?>

			<!-- HIDDEN SUBMENU START -->
			<div class="grid_16" id="hidden_submenu">
				<ul class="more_menu">
					<li>
						<a href="#">More link 1</a>
					</li>
					<li>
						<a href="#">More link 2</a>
					</li>
					<li>
						<a href="#">More link 3</a>
					</li>
					<li>
						<a href="#">More link 4</a>
					</li>
				</ul>
				<ul class="more_menu">
					<li>
						<a href="#">More link 5</a>
					</li>
					<li>
						<a href="#">More link 6</a>
					</li>
					<li>
						<a href="#">More link 7</a>
					</li>
					<li>
						<a href="#">More link 8</a>
					</li>
				</ul>
				<ul class="more_menu">
					<li>
						<a href="#">More link 9</a>
					</li>
					<li>
						<a href="#">More link 10</a>
					</li>
					<li>
						<a href="#">More link 11</a>
					</li>
					<li>
						<a href="#">More link 12</a>
					</li>
				</ul>
			</div>
			<!-- HIDDEN SUBMENU END -->

			<div class="clear"></div>

			<!-- This contains the hidden content for modal box calls -->
			<div class='hidden'>
				<div id="inline_example1" title="This is a modal box" style='padding:10px; background:#fff;'>
					<p>
						<strong>This content comes from a hidden element on this page.</strong>
					</p>

					<p>
						<strong>Try testing yourself!</strong>
					</p>
					<p>
						You can call as many dialogs you want with jQuery UI.
					</p>
				</div>
			</div>
		</div>
		
    
		<!-- WRAPPER END -->
		<!-- FOOTER START -->
		<div class="container_16" id="footer">
			<a href="www.scinformatica.cl">SC Informatica</a>
		</div>
		<!-- FOOTER END -->
		<?php //****************************************NUEVO REGISTRO
  //if(isset($_GET["editar"])){
  	
  //}
  //else{
  include "mantenedores/formulario_nuevo.php";
  //}
		?>

		<?php
		//******************************************************************************************************EDITABLES
		include "mantenedores/formulario_editar.php";

		?>


	</body>
	
</html>


